﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;
namespace DAL
{
    public class TimeTableDAL
    {
        DBHelper db = new DBHelper();
        public List<TimeTableModel> GetListAll()
        {
            string sql = $"select * from [dbo].[TimeTable]";
            List<TimeTableModel> list = new List<TimeTableModel>();
            DataTable dt = db.GetData(sql).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TimeTableModel DM = new TimeTableModel();
                DM.DutyDay =dt.Rows[i]["DutyDay"].ToString();
                DM.ClassTime = dt.Rows[i]["ClassTime"].ToString();
                DM.ClassSubject = dt.Rows[i]["ClassSubject"].ToString();
                DM.TeacherID = dt.Rows[i]["TeacherID"].ToString();
                DM.ClassRoom = dt.Rows[i]["ClassRoom"].ToString();
                list.Add(DM);
            }
            return list;
        }
        public List<TimeTableModel> GetListAllChaqin()
        {
            string sql = $"select * from [dbo].[RoomSelect]";
            List<TimeTableModel> list = new List<TimeTableModel>();
            DataTable dt = db.GetData(sql).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TimeTableModel DM = new TimeTableModel();
                DM.SelectDate = Convert.ToDateTime(dt.Rows[i]["SelectDate"].ToString());
                DM.RoomNo = Convert.ToInt32(dt.Rows[i]["RoomNo"].ToString());
                DM.RoomCount = dt.Rows[i]["RoomCount"].ToString();
                DM.RoomRemark = dt.Rows[i]["RoomRemark"].ToString();
                list.Add(DM);
            }
            return list;
        }
        public bool Add(TimeTableModel DM)
        {
            string sql = $"insert into[dbo].[StudentLeave](StudentName, StudentID, StudentEvent, LeaveTime, LeaveApprove)values('{DM.StudentName}','{DM.StudentID}','{DM.StudentEvent}','{DM.StudentLeaveTimeEvent}','')";
            if (db.SetData(sql))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool AddT(TimeTableModel DM)
        {
            string sql = $"insert into[dbo].[TeacherLeave](TeacherName, TeacherEvent, LeaveTime, TeacherLeaveApprove)values('{DM.TeacherName}','{DM.TeacherEvent}','{DM.LeaveTime}','')";
            if (db.SetData(sql))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        
    }
}
